package com.pshare.session.utils;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

public class SerializeUtil {

	public static Object getObjectFromBytes(byte[] value) throws IOException, ClassNotFoundException {
		ByteArrayInputStream bi = new ByteArrayInputStream(value);
		ObjectInputStream oi = new ObjectInputStream(bi);
		return oi.readObject();
	}

	public static byte[] getBytesFromObject(Object obj) throws IOException {
		ByteArrayOutputStream bo = new ByteArrayOutputStream();
		ObjectOutputStream oo = new ObjectOutputStream(bo);
		oo.writeObject(obj);
		return bo.toByteArray();
	}
}
